package com.ytrsoft;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.core.util.CharsetUtil;

import java.io.File;
import java.util.List;

public final class FileUtils {

    private FileUtils() {
        throw new UnsupportedOperationException();
    }

    private static File getFileAsResource(String fileName) {
        ClassPathResource resource = new ClassPathResource("");
        String path = resource.getAbsolutePath();
        return new File(path + fileName);
    }

    public static List<String> getPasswordList() {
        File fileAsResource = getFileAsResource("./password.txt");
        return FileUtil.readLines(fileAsResource, CharsetUtil.CHARSET_UTF_8);
    }

    public static void writeResultFile(String username, String password) {
        File fileAsResource = getFileAsResource("./result.txt");
        String sb = "username" +
                "=" +
                username +
                "\n" +
                "password" +
                "=" +
                password;
        FileUtil.writeBytes(sb.getBytes(), fileAsResource);
    }

    public static List<String> getUsernameList() {
        File fileAsResource = getFileAsResource("./username.txt");
        return FileUtil.readLines(fileAsResource, CharsetUtil.CHARSET_UTF_8);
    }

}